function varargout=DimReduction_Distribution(PP,SS,Type,varargin)

Flag_DistRed=   0;

switch Flag_DistRed
    case 0
        %% No State Space Reduction
        switch Type
            case 'Zip'
                QW          =   varargin{1};

                varargout{1}=   QW;
                varargout{2}=   [];
            case 'UnZip'
                Dist        =   varargin{1};

                varargout{1}=   Dist;
        end
    case 1
        %% State Space Reduction: Copula over (f,z) at each dimension of o
        Dim_f       =   SS.DistApp.fzo.UnitNum(1);
        Dim_z       =   PP.ExoState.IdioInc.N;
        Dim_o       =   PP.ExoState.Idio_FI.N*PP.ExoState.Idio_RI.N;
        switch Type
            case 'Zip'
                QW          =   varargin{1};

                QW_Mat      =   reshape(QW,[Dim_f*Dim_z,Dim_o]);
                CopulaF     =   cell(Dim_o,1);
                for ii=1:Dim_o
                    TempQW              =   QW_Mat(:,ii)/sum(QW_Mat(:,ii));
                    CopulaF{ii}         =   DistApp_Hist_QW2CopulaF([Dim_f,Dim_z],TempQW);
                end

                QW_fo       =   DistApp_Hist_MergeQW2Marginal([Dim_f,Dim_z,Dim_o],[1,3],QW);

                varargout{1}=   QW_fo;
                varargout{2}=   CopulaF;
            case 'UnZip'
                Dist        =   varargin{1};
                CopulaF     =   varargin{2};

                QW_zo       =   DistApp_Hist_MergeQW2Marginal([Dim_f,Dim_z,Dim_o],[2,3],SS.Dist_fzo.QW_fzo);
                MarginQW_fo =   reshape(Dist,[Dim_f,Dim_o]);
                MarginQW_zo =   reshape(QW_zo,[Dim_z,Dim_o]);
                MarginQW_fzo=   zeros(Dim_f*Dim_z,Dim_o);
                for ii=1:Dim_o
                    TempMarginQWCell ...
                                =   {MarginQW_fo(:,ii)/sum(MarginQW_fo(:,ii)),...
                                     MarginQW_zo(:,ii)/sum(MarginQW_zo(:,ii))};
                    MarginQW_fzo(:,ii) ...
                                =   DistApp_Hist_MarginCopulaF2QW(TempMarginQWCell,CopulaF{ii});
                end
                QW_fzo      =   bsxfun(@times,MarginQW_fzo,sum(MarginQW_fo,1));

                varargout{1}=   QW_fzo(:);
        end
        
    case 2
        %% State Space Reduction: Copula over f at each dimension of (z,o)
        Dim_f       =   SS.DistApp.fzo.UnitNum(1);
        Dim_z       =   PP.ExoState.IdioInc.N;
        Dim_o       =   PP.ExoState.Idio_FI.N*PP.ExoState.Idio_RI.N;
        switch Type
            case 'Zip'
                QW          =   varargin{1};
                
                CopulaF     =   DistApp_Hist_QW2CopulaF([Dim_f,Dim_z*Dim_o],QW);
                QW_f        =   DistApp_Hist_MergeQW2Marginal([Dim_f,Dim_z,Dim_o],[1],QW);

                varargout{1}=   QW_f;
                varargout{2}=   CopulaF;
            case 'UnZip'
                Dist        =   varargin{1};
                CopulaF     =   varargin{2};
                
                QW_f        =   Dist;
                QW_zo       =   DistApp_Hist_MergeQW2Marginal([Dim_f,Dim_z,Dim_o],[2,3],SS.Dist_fzo.QW_fzo);

                MarginQWCell=   {QW_f,QW_zo};
                QW_fzo      =   DistApp_Hist_MarginCopulaF2QW(MarginQWCell,CopulaF);
             
                varargout{1}=   QW_fzo(:);
        end
end

